﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Web;

namespace CustomerServiceCenter.Models
{
    public class EnumDescripte
    {
        public static string GetEnumDeScription(Enum en)
        {
            Type type = en.GetType();
            MemberInfo[] memInfo = type.GetMember(en.ToString());
            if (memInfo != null && memInfo.Length > 0)
            {
                object[] attributes = memInfo[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (attributes != null && attributes.Length > 0)
                {
                    return ((DescriptionAttribute)attributes[0]).Description;
                }
                else
                {
                    return "UNKNOWN";
                }
            }
            return en.ToString();
        }
        public static string GetName(System.Type type, object value)
        {
            try
            {
                return Enum.GetName(type, value);
            }
            catch (Exception)
            {
                return "UNKNOWN";
            }
        }
    }
}